package com.supermap.dataservice.cloud.loginlog;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.cloud.loginlog.LoginLogService;
import com.supermap.dubbo.api.cloud.loginlog.loginlog;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author aqua
 * @description
 * @date 2018年12月04 上午 10:28
 * @email 1301584033@qq.com
 */
@Service
public class LoginLogServiceImpl implements LoginLogService {

    @Resource
    private LoginLogMapper loginLogMapper;

    @Override
    public JSONUtil getSysLoginLog(loginlog loginlog, Table table) {
        JSONUtil jsonUtil = new JSONUtil();

            List<loginlog> list = loginLogMapper.getSysLoginLog(loginlog,table);
            int count = loginLogMapper.getSysLoginLogCount(loginlog);
            if(list!=null&&!list.isEmpty()){
                table.setData(list);
                table.setCount(count);
                jsonUtil.setMsg("Get users success！");
                jsonUtil.setIsSuccess(true);
                jsonUtil.setCode(200);
                jsonUtil.setData(table);
            }else{
                jsonUtil.setMsg("Get users fail！");
                jsonUtil.setIsSuccess(true);
                jsonUtil.setCode(200);
            }
        return jsonUtil;
    }

    @Override
    public JSONUtil insertLoginLog(loginlog loginlog) {
        int count=loginLogMapper.insertLoginLog(loginlog);
        if(count>0){
            return  new JSONUtil();
        }
        return  new JSONUtil().setMsg("操作失败!").setCode(100).setIsSuccess(false);
    }

    @Override
    public JSONUtil getLoginLogByUserIdAndareaCodeOrdTime(String areaCode, String beginTime, String endTime, Integer pageNum, Integer pageSize) {
     pageNum=(pageNum-1)*pageSize;
        return new JSONUtil().setData(loginLogMapper.
                getLoginLogByUserIdAndareaCodeOrdTime(areaCode,beginTime,endTime,pageNum,
                        pageSize)).setCountSum(loginLogMapper.getLoginLogByUserIdAndareaCodeOrdTimeCount(
                areaCode,beginTime,endTime
        ));
    }


    @Override
    public JSONUtil getPageAllLoginLogByUserIdorTime(String userId, String beginTime, String endTime, Integer pageNum, Integer pageSize) {
        pageNum=(pageNum-1)*pageSize;
        return new JSONUtil().setData(loginLogMapper.
                getPageAllLoginLogByUserIdorTime(userId,beginTime,endTime,pageNum,
                        pageSize)).setCountSum(loginLogMapper.getPageAllLoginLogByUserIdorTimeCount(
                userId,beginTime,endTime
        ));
    }


}
